import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpEventType } from '@angular/common/http';

import { Observable } from "rxjs/Observable";
import 'rxjs/add/operator/do';
import "rxjs/Rx";
/*
  Generated class for the HttptimingProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class HttptimingProvider implements HttpInterceptor {

	constructor() {

	}

	intercept(req: HttpRequest < any > , next: HttpHandler): Observable < HttpEvent < any >> {
		// 在这里写请求发起之前的行为
		return next.handle(req).do(event => {
			// 在这里写请求完成后的行为
			if(event.type == HttpEventType.Sent) {

			} else if(event.type == HttpEventType.UploadProgress) {

			} else if(event.type == HttpEventType.ResponseHeader) {

			} else if(event.type == HttpEventType.DownloadProgress) {

			} else if(event.type == HttpEventType.Response) {

			}
			return event;
		});
	}
}